import React from 'react';
import classnames from 'classnames';
import './index.less';
export default class view extends React.Component {
    static propTypes = {
        className: React.PropTypes.string,
        title: React.PropTypes.string,
        more: React.PropTypes.any,
        type: React.PropTypes.string,
    };


    constructor(props, context) {

        super(props, context);

        this.state = {

        };
    }
    componentWillMount() {
        this._isMounted = true;

    }

    componentDidMount() {

    }

    componentWillUnmount() {
        this._isMounted = false;
    }

    renderTitle(text, left = null) {
        const classNames = classnames('orin-sw-repanel-title', left);
        return (
            <div className={classNames}>{text}</div>
        );
    }

    renderMore(any, right = null) {
        const classNames = classnames('orin-sw-repanel-more', right);
        return (
            <div className={classNames}>{any}</div>
        );
    }

    renderHeader() {
        if (this.props.title && this.props.more) {
            return (
                <div className="orin-sw-repanel-header">
                    {this.renderTitle(this.props.title,'left')}
                    {this.renderMore(this.props.more,'right')}
                </div>
            );
        } else if (this.props.title) {
            return (
                <div className="orin-sw-repanel-header">
                    {this.renderTitle(this.props.title)}
                </div>
            );
        } else if (this.props.more) {
            return (
                <div className="orin-sw-repanel-header">
                    {this.renderTitle(this.props.more)}
                </div>
            )
        }
    }

    renderMainer() {
        if (this.props.title || this.props.more) {
            return (
                <div className="orin-sw-repanel-content">{this.props.children}</div>
            );
        } else {
            return this.props.children;
        }

    }

    render() {
        const classNames = classnames({
            'orin-sw-repanel-root': true,
            [this.props.className]: this.props.className ? true : false,
            ['orin-sw-repanel-' + this.props.type]: this.props.type ? true : false,
            'padding': !this.props.title && !this.props.more
        });
        return (
            <div className={classNames} >
                {this.renderHeader()}
                {this.renderMainer()}
            </div>
        );
    }
}
